package com.mytest.test02;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Resource {

    private Integer num = 0;


//    Lock lock = new ReentrantLock();

    public synchronized void increment() throws InterruptedException {
        while (num != 0) {
            this.wait();
        }
        this.num++;
        System.out.println(Thread.currentThread().getName() + "::" + num);
        this.notifyAll();
    }

    public synchronized void decrement() throws InterruptedException {
        while (num == 0) {
            this.wait();
        }
        this.num--;
        System.out.println(Thread.currentThread().getName() + "::" + num);
        this.notifyAll();
    }

}
